package app;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
/**
 * Holds the network settings.  This is the singleton because these 
 * settings are "system-wide". 
 * 
 * @author Kristopher L. Kalish, James Madison University
 * @version 1 - February 21, 2008
 */
public class NetworkConfig
{
	private static NetworkConfig instance; //singleton guy
	
	private int    eventPort, modelPort;
	private String masterHost;

	private NetworkConfig()
	{
    	Properties netConfig = new Properties();
    	
    	try {
    		netConfig.load(new FileInputStream(new File("network.cfg")));
    	} catch(IOException ioe) {
    		ioe.printStackTrace();
    	}
    	
    	masterHost = (String) netConfig.getProperty("master");
    	eventPort  = Integer.parseInt((String) netConfig.get("eventPort"));
    	modelPort  = Integer.parseInt((String) netConfig.get("modelPort"));
	}
	
	public static NetworkConfig getInstance()
	{
		if(instance == null)
			instance = new NetworkConfig();
		
		return instance;
	}
	
	public int getEventPort()
	{
		return eventPort;
	}
	
	public int getModelPort()
	{
		return modelPort;
	}
	
	public String getMasterHost()
	{
		return masterHost;
	}
}
